<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 解构赋值

    // this指向全局
    let fun = function () {
        console.log(this.name);
    }
    //this为静态,始终指向声明变量时作用域下的this
    const fun1 = () => {
        console.log(this.name);
    }
    window.name = '111';
    const school = {
        name: '222'
    }
    // fun();
    // fun1();
    //利用call方法改变this指向
    // fun.call(school);
    // fun1.call(school);


    //----------------------------
    //箭头函数无法构造实例化对象 构造实例化对象 
    // let a = function (name, age) {
    //     this.name = name;
    //     this.age = age;
    // }
    // let me = new a('hong', 20);

    // let me1 = new a('guan', 20);
    // console.log(me);
    // console.log(me1);

    //----------------------------
    // arguments
    // 获取函数内部实参的类数组对象
    // let arg = function (name, num, all) {
    //     console.log(arguments);
    // }
    // arg();
    // console.log(arg.school);

    //-----------------------------------
    //箭头函数简写
    //省略小括号，当形参只有一个时
    let sx = name => {
        console.log(this.name);
    }
    window.name = 'wsnd';
    sx();
    //省略花括号，代码体为一句时，此时return必须省略，并且语句执行结果为函数返回值
    let re = n => n + n;
    console.log(re(1));

    //----------------------------
    //箭头函数使用场景

    //filter测试函数所有元素，符合条件的返回新数组
    const arr = [1, 2, 34, 5, 6, 7, 8];
    //回调函数
    let num = arr.filter(n => n % 2 === 0);
    console.log(num);

</script>

</html>